

function getCanvasMergeImg() { //使用 canvas 合成图片
  var proportion = this.proportion * 2  //调整清晰度，同时需修改css的缩放倍数
  var that = this
  $('#qrcode').qrcode({
    render: "canvas",
    text: that.message.activeUrl
  });
  var base64 = $('#qrcode canvas')[0].toDataURL("image/png"); //获取二维码base6
  var canvas = document.createElement("canvas");
  var width = 382 * proportion
  var height = 679 * proportion
  canvas.width = width;
  canvas.height = height;
  var context = canvas.getContext("2d");
  context.rect(0, 0, canvas.width, canvas.height);
  context.fillStyle = "#fff";
  context.fill();
  var myImage = new Image();
  myImage.src = "./img/backg.png"; //背景图片 你自己本地的图片或者在线图片
  // myImage.crossOrigin = 'Anonymous';
  myImage.onload = function () {
    context.drawImage(myImage, 0, 0, width, height);
    var myImage2 = new Image();
    myImage2.src = base64; //你自己本地的图片或者在线图片
    // myImage2.crossOrigin = 'Anonymous';
    myImage2.onload = function () {
      var top = 430 * proportion
      var left = 90 * proportion
      var width = 200 * proportion
      var height = 200 * proportion
      context.drawImage(myImage2, left, top, width, height);
      var myImage3 = new Image();
      myImage3.src = './img/icon.png';
      myImage3.onload = function () {
        var top = 505 * proportion
        var left = 163 * proportion
        var width = 50 * proportion
        var height = 50 * proportion
        context.drawImage(myImage3, left, top, width, height);
        that.shareImgBase64 = canvas.toDataURL("image/png"); //"image/png" 这里注意一下
        var img = document.getElementById('avatar');
        // document.getElementById('avatar').src = that.shareImgBase64;
        img.setAttribute('src', that.shareImgBase64);
      }
    }
  }
}
